****************************************************************************************************
****************************************************************************************************
*Replication file for:
*The Importance of a Liberal Power's Attention to Democratic Elections Around the World
*Johannes Bubeck Ashrakat Elshehawy Nikolay Marinov Federico Nanni
****************************************************************************************************
****************************************************************************************************


cd "/Data"
clear
use neldaprep




************************
********FIGURE 4A*******
************************

*Important note - plrase read

*****
*		Figure 4 (a), we observe the differences of the means and their confidence intervals
*		Please note the interpretation of these coefficients and confidence intervals should be reversed
*       This is the case as STATA reports the difference between the 0 not close to elections group and the 1 close elections group. One implication is that when bias is greater in the latter group, this difference is negative. Since in the paper we always speak of the difference between the close to elections group and the one away from elections, we reverse the quantity reported by STATA. Thus, one bias close to elections is greater, our reported result is always positive.
*      Results of these ttests below will be used in R using the code called 3_Figure4.R to plot the figure
*****


ttest bias if strpos(lower(nelda3),"y")>0 & strpos(lower(nelda4),"y")>0 & strpos(lower(nelda5),"y")>0, by(uselein15)


* Store the results
return list

* Calculate the confidence intervals
scalar mean_diff =  r(mu_2)-r(mu_1) 
scalar se = r(se)
scalar  ci_lower= mean_diff - 1.96*se
scalar  ci_upper = mean_diff + 1.96*se

clear
set obs 1
gen mean_difference = mean_diff
gen lower_confidence = ci_lower
gen upper_confidence = ci_upper
gen election="ALL"
gen months=1.5
* Export the results to a CSV file
export delimited using resultsfigure4_1.csv, replace




*****
*		Figure 4 (a), 2nd bar
*****
clear
cd "/Data"

use neldaprep



ttest bias if strpos(lower(nelda3),"y")>0 & strpos(lower(nelda4),"y")>0 & strpos(lower(nelda5),"y")>0, by(uselein3)

* Store the results
return list

* Calculate the confidence intervals
scalar mean_diff =  r(mu_2)-r(mu_1) 
scalar se = r(se)
scalar ci_upper = mean_diff - 1.96*se
scalar ci_lower = mean_diff + 1.96*se

clear
set obs 1
gen mean_difference = mean_diff
gen lower_confidence = ci_lower
gen upper_confidence = ci_upper
gen election="ALL"
gen months=3
* Export the results to a CSV file
export delimited using resultsfigure4_2.csv, replace





*****
*		Figure 4 (a), 3d bar
*****
cd "/Data"
clear
use neldaprep



ttest bias if strpos(lower(nelda3),"y")>0 & strpos(lower(nelda4),"y")>0 & strpos(lower(nelda5),"y")>0, by(uselein6)

* Store the results
return list

* Calculate the confidence intervals
scalar mean_diff =  r(mu_2)-r(mu_1) 
scalar se = r(se)
scalar ci_lower = mean_diff - 1.96*se
scalar ci_upper= mean_diff + 1.96*se

clear
set obs 1
gen mean_difference = mean_diff
gen lower_confidence = ci_lower
gen upper_confidence = ci_upper
gen election="ALL"
gen months=6
* Export the results to a CSV file
export delimited using resultsfigure4_3.csv, replace


*****
*		Figure 4 (a), 4th bar -> this one is slightly off but the message does not change so maybeleave
*****
cd "/Data"
clear
use neldaprep


ttest bias if strpos(lower(nelda3),"y")>0 & strpos(lower(nelda4),"y")>0 & strpos(lower(nelda5),"y")>0, by(uspreselein15) 

* Store the results
return list

* Calculate the confidence intervals
scalar mean_diff =  r(mu_2)-r(mu_1) 
scalar se = r(se)
scalar ci_lower = mean_diff - 1.96*se
scalar ci_upper= mean_diff + 1.96*se

clear
set obs 1
gen mean_difference = mean_diff
gen lower_confidence = ci_lower
gen upper_confidence = ci_upper
gen election="Pres"
gen months=1.5
* Export the results to a CSV file
export delimited using resultsfigure4_4.csv, replace


*****
*		Figure 4 (a), 5th bar
*****
clear
cd "/Data"

use neldaprep


ttest bias if strpos(lower(nelda3),"y")>0 & strpos(lower(nelda4),"y")>0 & strpos(lower(nelda5),"y")>0, by(uspreselein3) 
* Store the results
return list

* Calculate the confidence intervals
scalar mean_diff =  r(mu_2)-r(mu_1) 
scalar se = r(se)
scalar ci_lower = mean_diff - 1.96*se
scalar ci_upper= mean_diff + 1.96*se

clear
set obs 1
gen mean_difference = mean_diff
gen lower_confidence = ci_lower
gen upper_confidence = ci_upper
gen election="Pres"
gen months=3
* Export the results to a CSV file
export delimited using resultsfigure4_5.csv, replace


*****
*		Figure 4 (a), 6th bar
*****
clear
cd "/Data"

use neldaprep



ttest bias if strpos(lower(nelda3),"y")>0 & strpos(lower(nelda4),"y")>0 & strpos(lower(nelda5),"y")>0, by(uspreselein6) 

* Store the results
return list

* Calculate the confidence intervals
scalar mean_diff =  r(mu_2)-r(mu_1) 
scalar se = r(se)
scalar ci_lower = mean_diff - 1.96*se
scalar ci_upper= mean_diff + 1.96*se

clear
set obs 1
gen mean_difference = mean_diff
gen lower_confidence = ci_lower
gen upper_confidence = ci_upper
gen election="Pres"
gen months=6
* Export the results to a CSV file
export delimited using resultsfigure4_6.csv, replace




*outputs created resultsfigure4_1.csv,resultsfigure4_2.csv ,
*resultsfigure4_3.csv ,resultsfigure4_4.csv ,resultsfigure4_5.csv ,resultsfigure4_6.csv 
*these will be used using R code 3_Figure4.R to plot the results 





************************************************************************************************
********FIGURE 4B*******
************************************************************************************************

clear
cd "/Data"

use neldaprep




   
*****
*		Figure 4 (b) (1) 
*****
   
   
xi: regress bias uspreselein15 year changed i.ccode ,robust


*****
*		Figure 4 (b) (2) 
*****
   
   
xi: regress bias uspreselein3 year changed i.ccode, robust


*****
*		Figure 4 (b) (3) 
*****
   
   
xi: regress bias uspreselein6 year changed i.ccode, robust



	